/*
 * UWT 2014
 */
package model;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import org.tc33.jheatchart.HeatChart;

/**
 * @author Jamada
 */
public class HeatMap {
    
	/**
	 * Default data for heat map.
	 */
    private static final double[][] DATA = new double[][]{{3,2,3,4,5,6}, 
                                                          {2,3,4,5,6,7}, 
                                                          {3,4,5,6,7,6}, 
                                                          {4,5,6,7,6,5}};
    /**
     * Default protein IDs.
     */
    private final static Object[] Y_VALUES = new Object[]{"P15121", "Q13427", "P00918", "P22749"};
    /**
     * Default compound names.
     */
    private final static Object[] X_VALUES = new Object[]{"mitoxantrone", "clofarabine", "daunorubicin", "etoposide", "fludarabine", "norfloxacin"};
    
    /**
     * Heat map as HeatChart object.
     */
    private final HeatChart map;
    
    /**
     * Constructs HeatMap object.
     * 
     * @param mapData HeatMapData used to create HeatMap.
     */
    public HeatMap(final HeatMapData mapData) {
        this.map = new HeatChart(mapData.getData());
        this.map.setYValues(mapData.getYValues());
        this.map.setXValues(mapData.getXValues());
        this.map.setXAxisLabel(mapData.getXAxisLabel());
        this.map.setYAxisLabel(mapData.getYAxisLabel());
        this.map.setCellSize(mapData.getCellSize());
        this.map.setLowValueColour(mapData.getLowColor());
        this.map.setHighValueColour(mapData.getHighColor());
        this.map.setXValuesHorizontal(mapData.getXValuesHorizontal());
        if (mapData.getTitle() != null) {
        	this.map.setTitle(mapData.getTitle());
            this.map.setTitleFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
        }
    }
    
    /**
     * Constructs default heat map object.
     */
    public HeatMap() {
        this(new HeatMapData(DATA, X_VALUES, Y_VALUES));
    }
    
    /**
     * @return Returns heat map image.
     */
    public Image getImage() {
        return this.map.getChartImage();
    }
    
    /**
     * Saves heat map image to specified file name.
     * 
     * @param name Name of file.
     */
    public void saveImageToFile(String name) {

        try {
            this.map.saveToFile(new File(name));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Sets color of low values in heat map.
     * 
     * @param color Color of low values.
     */
    public void setLowColor(final Color color) {
    	this.map.setLowValueColour(color);
    }
    
    /**
     * Sets color of high values in heat map.
     * 
     * @param color Color of high values.
     */
    public void setHighColor(final Color color) {
    	this.map.setHighValueColour(color);
    }
}